package com.wiloon.java8x.io.socket;

/**
 * Created by roy.wang on 2017/4/19;
 */

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class DstServiceImpl implements Runnable {
    Socket socket = null;

    public DstServiceImpl(Socket s) {
        this.socket = s;
    }

    public void run() {
        try {
            InputStream ips = socket.getInputStream();
            OutputStream ops = socket.getOutputStream();
            while (true) {
                byte[] bt = StreamTool.readStream(ips);
                String str = new String(bt);
                System.out.println("receive msg：" + str);
                String restr = "msg received.";
                ops.write(restr.getBytes());
                ops.flush();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}